#include "statisticalwidget.h"
#include "ui_statisticalwidget.h"

#include <QGraphicsView>

void StatisticalWidget::pie_init(void)
{
    series_pie = new QPieSeries();
    series_pie->setHoleSize(0.35);//设置中心圆大小
    //设置每个饼块的大小
    series_pie->append("技术部",4.2);
    series_pie->append("财务部",56.4);
    series_pie->append("人事部",23.8);

    //添加颜色
    series_pie->slices().at(0)->setColor(mySkin[curr_skin].color_1);
    series_pie->slices().at(1)->setColor(mySkin[curr_skin].color_2);
    series_pie->slices().at(2)->setColor(mySkin[curr_skin].color_3);


    Chart_pie = new QChart();
    //chart开始动画模式
    Chart_pie->setAnimationOptions(QChart::SeriesAnimations);
    Chart_pie->setAnimationDuration(500);

    Chart_pie->addSeries(series_pie);
    Chart_pie->legend()->setAlignment(Qt::AlignBottom);
    Chart_pie->legend()->setFont(QFont("Arial",12));
    QFont font_spline("Arial",16);
    Chart_pie->setTitleFont(font_spline);
    Chart_pie->setTitle("部门正常出勤率占比");           // 设置标题

    ui->graphicsView_pie->setRenderHint(QPainter::Antialiasing);// 设置抗锯齿
    ui->graphicsView_pie->setChart(Chart_pie);
}


//刷新数据
void StatisticalWidget::slot_pie_roll(void)
{

    int data1 = qrand()%30;
    int data2 = qrand()%30;
    int data3 = qrand()%40;

    series_pie->clear();
    series_pie->setHoleSize(0.35);
    //重新添加数据
    series_pie->append(QString("技术部"),data1);
    series_pie->append(QString("财务部"),data2);
    series_pie->append(QString("人事部"),data3);

    //设置颜色
    // series_pie->slices().at(0)->setColor(mySkin[curr_skin].color_1);
    // series_pie->slices().at(1)->setColor(mySkin[curr_skin].color_2);
    // series_pie->slices().at(2)->setColor(mySkin[curr_skin].color_3);
}

void StatisticalWidget::do_pie_roll(const QString &Title, const QMap<QString, double> &deptMap)
{
    Chart_pie->setTitle(Title);           // 设置标题

    series_pie->clear();
    series_pie->setHoleSize(0.35);
    //重新添加数据
    for(const double &data : deptMap)
    {
        series_pie->append(deptMap.key(data), data);
    }
}
